package com.hospital.config;


import com.hospital.controller.interceptor.AdminLoginInterceptor;
import com.hospital.controller.interceptor.DoctorLoginInterceptor;
import com.hospital.controller.interceptor.UserLoginInterceptor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.ArrayList;
import java.util.List;

@Configuration
public class WebConfigurer implements WebMvcConfigurer {

    @Autowired
    private UserLoginInterceptor userLoginInterceptor;

    @Autowired
    private AdminLoginInterceptor  adminLoginInterceptor;

    @Autowired
    private DoctorLoginInterceptor doctorLoginInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        //拦截路径
        InterceptorRegistration ir = registry.addInterceptor(userLoginInterceptor);
        ir.addPathPatterns("/**/pages/userFrame.html");
//        //不拦截路径
        List<String> irs = new ArrayList<>();
        irs.add("/**/userLogin.html");
        ir.excludePathPatterns(irs);

        InterceptorRegistration ir2 = registry.addInterceptor(adminLoginInterceptor);
        ir2.addPathPatterns("/**/pages/adminFrame.html");
        ir2.addPathPatterns("/**/pages/doctorSit.html");
        ir2.addPathPatterns("/**/pages/addDoctorSit.html");
        ir2.addPathPatterns("/**/pages/admin.html");

        List<String> irs2 = new ArrayList<>();
        irs2.add("/**/adminLogin.html");
        ir2.excludePathPatterns(irs2);


        InterceptorRegistration ir3 = registry.addInterceptor(doctorLoginInterceptor);
        ir3.addPathPatterns("/**/pages/doctorFrame.html");

        List<String> irs3 = new ArrayList<>();
        irs3.add("/**/doctorLogin");
        ir3.excludePathPatterns(irs3);


    }
}
